In [1]:
import sys

sys.path.insert(0, '../..')
import base_node_rpc as bn
import rpc_stream as rs
import pandas as pd
from IPython.display import display

Connect to serial device


In [2]:
proxy = bn.proxy.connect(rs.Proxy, name='rpc_stream')
print 'Connected to device on port:', proxy._serial.port
proxy.properties()


Connected to device on port: /dev/ttyUSB0
Out[2]:
base_node_software_version                                                 0.11
name                                                                 rpc_stream
manufacturer                                                        Wheeler Lab
url                           http://github.com/wheeler-microfluidics/rpc-st...
software_version                                                            0.1
dtype: object

Send 4 echo requests, each triggering 2 stream packets

Note that stream responses are processed automatically in the background, and added to a stream queue.


In [3]:
for i in range(4):
    proxy.stream_echo('hello %s' % i, 2)

Display info for packets found in stream queue


In [4]:
packets = [list(proxy.queues.stream.get()) for i in xrange(proxy.queues.stream.qsize())]
if packets:
    df_packets = pd.DataFrame(packets, columns=['timestamp', 'packet'])
    df_packets['iuid'] = df_packets.packet.map(lambda p: p.iuid)
    df_packets['data'] = df_packets.packet.map(lambda p: p.data())
    display(df_packets)
#     display(df_packets.groupby('iuid').agg({'data': lambda v: ''.join(v)}))


timestamp packet iuid data
0 2015-08-13 10:40:29.709390 |||�shello 0�D 1717 hello 0
1 2015-08-13 10:40:29.711371 |||�shello 0�D 1717 hello 0
2 2015-08-13 10:40:29.719463 |||�shello 1c� 1718 hello 1
3 2015-08-13 10:40:29.720216 |||�shello 1c� 1718 hello 1
4 2015-08-13 10:40:29.727225 |||�shello 2b� 1719 hello 2
5 2015-08-13 10:40:29.728236 |||�shello 2b� 1719 hello 2
6 2015-08-13 10:40:29.735196 |||�shello 3� 1720 hello 3
7 2015-08-13 10:40:29.736219 |||�shello 3� 1720 hello 3